<?php
namespace Home\Controller;
use Think\Controller;
class MessageController extends Controller {
	//生活类帖子查询
	 public function tiezi(){
		             $class=$_GET['class'];
		             $tie=D('Tie');		 
		             $where='class='."\"".$class."\"";
					 $count=$tie->where($where)->count();				 
					 $Page=new \Think\Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数(25)
					 $show= $Page->show();// 分页显示输出// 查找类别是生活类和置顶的用户数据返回数据
					 $Page->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%');					 
					 $mt=$tie->where($where)->limit($Page->firstRow.','.$Page->listRows)->select();						
					 $this->assign('list',$mt)->assign('show',$show);//参数$arr放入list中传给模板文件     
				 
				 
					  $tie=D('Tie');
					  $jing='1';
					  $where1='jing='.$jing.' AND class='."\"".$class."\"";					  
					  $count1=$tie->where($where1)->count();
					  $Page1=new \Think\Page($count1,5);// 实例化分页类 传入总记录数和每页显示的记录数(25)
					  // 查找类别是生活类和置顶的用户数据返回数据
					  $show1= $Page1->show();// 分页显示输出 
					  $Page1->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%');	
					  $mt1=$tie->where($where1)->limit($Page1->firstRow.','.$Page1->listRows)->select();
					 // $this->assign('arr',$arr);//参数$arr放入list中传给模板文件
					  $this->assign('list1',$mt1)->assign('show1',$show1);//参数$arr放入list中传给模板文件     
				     

					  $tie=D('Tie');
					  $ding='1';
					  $where2='ding='.$ding.' AND class='."\"".$class."\"";	
					  $count2=$tie->where($where2)->count();
					  $Page2=new \Think\Page($count2,1);// 实例化分页类 传入总记录数和每页显示的记录数(25)
					 // 查找类别是生活类和置顶的用户数据返回数据
					  $show2= $Page2->show();// 分页显示输出
					  $Page2->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%');	
					  $md=$tie->where($where2)->limit($Page2->firstRow.','.$Page2->listRows)->select();
					  $this->assign('list2',$md)->assign('show2',$show2);//参数$arr放入list中传给模板文件     
					  $this->display('shenghuo');
					 
	} 
	//热门动态
	public function remen(){
		             $tid = $_GET['tid'];
		             $where['tid']=$tid;	
                     $data = M('user  as  a')->join('lt_tie  as  b  on b.uid = a.id')->where($where)->select(); 				 
                     $this->assign('list',$data);	
				     $this->display();				 
	}
	
	
/* namespace Home\Controller;
use Think\Controller;
class RemindController extends Controller{
	public function download() {
		$dl=M('Tie');
		$aid=1;
		$tid=1;
		$where=$tid;
		$data=$dl->where($where)->select();
		$this->assign('data',$data);
		$this->display();
		if($data['fid']!=null && $data['sid']!=null){
			$Http = new \Org\Net\Http();
			$filename="Public/file/test.doc";//之前上传过的文件的路径
			$showname="test.doc";//你想让它显示的文件的名字
			$content = "this";  // 表示下载的文件内容只有this
			$Http::download($filename, $showname, $content);
		}else{
			echo '请先回复！';
		}
	}
}
 *///楼主删除回复
 public function dele(){
	
				  $where['fid']=$_GET['cid'];
				  $where['tid']=$_GET['tid'];
				  $answer=M('Answer');
				  $f=$answer->where($where)->delete();
				  if($f){
					   $this->success('删除成功');
				  }else{
					   $this->error('删除失败');
				  }
			 }
	 
	 
	 
 
	//给楼主的回复
	public function huifu(){
		if(!isset($_SESSION['username']) || $_SESSION['username']==''){
			//$this->redirect('Index/index',array('tid' => $data2['tid']),5, '请先登录再回复');
			$this->success('请先登录再回复',U('Index/index'));

		}else{
		            $data2['tid'] =$_GET['tid'];
                    $data2['acontent'] = $_POST['huifu'];
                    $data2['atime'] = time();
					$data2['fid'] = $_SESSION['uid'];
					$data2['sid'] = 0;
					$data2['look'] = 0;
					dump($data2);
                    $Answer = M('Answer');
                    $Answer->data($data2)->add();
					$User=M('User');
					$where['uid']=$_SESSION['uid'];
					$User->where($where)->setInc('exper',3);
	                $this->redirect('Message/remen',array('tid' => $data2['tid']));//跳到另一个页面另一个方法并且把tid也传去
	}}
	public function huifu2(){
if(!isset($_SESSION['username']) || $_SESSION['username']==''){
			//$this->redirect('Index/index',array('tid' => $data2['tid']),5, '请先登录再回复');
			$this->success('请先登录再回复',U('Index/index'));

		}else{	
		            $data3['tid'] =$_GET['tid'];
					$data3['fid'] =$_GET['fid'];
                    $data3['acontent'] = $_POST['huifu2'];
                    $data3['atime'] = time();
					$data3['sid'] = $_SESSION['uid'];
					$data3['look'] = 0;
                    $Answer = M('Answer');
                    $Answer->data($data3)->add();
					$User=M('User');
					$where['uid']=$_SESSION['uid'];
					$User->where($where)->setInc('exper',3);
	                $this->redirect('Message/remen',array('tid' => $data3['tid']));//跳到另一个页面另一个方法并且把tid也传去
	}}


public function doMess(){
		
		$sex=$_POST['sex'];
		$year=$_POST['year'];
		$month=$_POST['month'];
		$day=$_POST['day'];
		$phone=$_POST['phone'];
		$jianjie=$_POST['jianjie'];
		$birth=$year.'/'.$month.'/'.$day;
		$username=$_SESSION['username'];
		$where['username']=$username;
		$user=M('User');
		$user->sex=$sex;
		$user->birth=$birth;
		$user->phone=$phone;
		$user->intro=$jianjie;
		$arr=$user->where($where)->save();
		   if($arr){
					//$this->success('修改成功');
					$this->redirect('Mypage/mypage');
		   }else {
		  		    $this->error('修改失败');
	 	   }
		   
		   
	}
	 public function doTou(){
		 
		  $user=M('User');
		  $username=$_SESSION['username'];
		  $upload = new \Think\Upload();// 实例化上传类
		  $upload->rootPath='./Public/uploads/'; // 设置附件上传根目录
		  $upload->autoSub  = false;
		  $info=$upload->upload();
		  if(!$info) { 
			  $this->error($upload->getError());
		  }
		  $user->head=$info["filename"]['savename'];
		  $where['username']=$username;
		  $arr=$user->where($where)->save();
		   if($arr){
					//$this->success('上传成功');
					$this->redirect('Mypage/mypage');
		   }else {
		  		    $this->error('上传失败');
	 	   }
	}
	
	 public function doLook(){
		 $v=$_POST['v'];
		 $answer=M('Answer');
		 $where['aid']=$v['aid'];
		 $answer->look=1;
		 $answer->where($where)->save();
		 $this->redirect('Mypage/mypage');
	 }
	 
	 //同意就把状态改为1
		public function doSavemsg(){
			$msg=M('Friends');
			$where['id']=$_GET['id'];
			$state['state']=1;
			$result=$msg->field('state')->where($where)->save($state);
			$this->redirect('Mypage/mypage');
			
		}
	//拒绝就把状态改为2
		public function doSavemsg1(){
			$msg=M('Friends');
			$where['id']=$_GET['id'];
			$state['state']=2;
			$result=$msg->field('state')->where($where)->save($state);
			$this->redirect('Mypage/mypage');
			
		}

    //收藏帖子
			   public function doShou(){
				  $where['id']=$_SESSION['uid'];
				  $tid=$_GET['tid'];
				  $user=M('User');
				  $u=$user->where($where)->find();
				  $user->collect=$u['collect'].$tid.',';
				  $f=$user->where($where)->save();
				  if($f){
					   $this->success('收藏成功');
				  }else{
					   $this->error('收藏失败');
				  }
			 }

}
?>